const { flowRight } = require('lodash');
const fp = require('lodash/fp');
const { Maybe, Container } = require('./support');

// 练习 1

const may = Maybe.of([5, 6, 11]);

const ex1 = x => arr => fp.map(fp.add(x), arr);

// const r = may.map(ex1(2));
// console.log(r);


// 练习 2
const xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);

const ex2 = arr => fp.first(arr);

// const r = xs.map(ex2);
// console.log(r);

// 练习 3
const safeProp = fp.curry(function(x, o) {
  return Maybe.of(o[x]);
});
const user = { id: 2, name: 'Albert' };

const ex3 = user => safeProp('name', user).map(fp.first)

// console.log(ex3(user));

// 练习 4
const ex4 = (n) => Maybe.of(n).map(parseInt);
// console.log(ex4('123'));
// console.log(ex4());